<template>
  <!-- 添加或修改检验标准对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="检验项目" prop="area">
                <el-select v-model="form.area" placeholder="请选择检验项目">
                  <el-option v-for="dict in dict.type.factory_test_item" :key="dict.value"
                             :label="dict.label" :value="dict.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="产品id" prop="goodsId">
                <el-input v-model="form.goodsId" placeholder="请输入产品id"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="产品名称" prop="goodsName">
                <el-input v-model="form.goodsName" placeholder="请输入产品名称"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="产品编码" prop="goodsCode">
                <el-input v-model="form.goodsCode" placeholder="请输入产品编码"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="产品型号" prop="goodsModel">
                <el-input v-model="form.goodsModel" placeholder="请输入产品型号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="属性名称" prop="propName">
                <el-input v-model="form.propName" placeholder="请输入属性名称"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="属性汉字" prop="propNameCh">
                <el-input v-model="form.propNameCh" placeholder="请输入属性汉字"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="最大值" prop="propValueMax">
                <el-input v-model="form.propValueMax" placeholder="请输入最大值"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="最小值" prop="propValueMin">
                <el-input v-model="form.propValueMin" placeholder="请输入最小值"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';

export default {
  name: "FactoryTestStandardFormBak",
  dicts: ['factory_test_item'],
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      url: {
        getById: '/factoryTestStandard/factoryTestStandard/',
        add: '/factoryTestStandard/factoryTestStandard/add',
        edit: '/factoryTestStandard/factoryTestStandard/edit',
      },
    };
  },
  created() {

  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        goodsId: null,
        goodsName: null,
        goodsCode: null,
        goodsModel: null,
        testType: null,
        propName: null,
        propNameCh: null,
        propValueMax: null,
        propValueMin: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加检验标准";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改检验标准";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.edit, this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.add, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },





  }
};
</script>
